﻿using System.Linq;
using Yz.Base;
using Yz.DataAccess.DbAccessses.Interface;
using Yz.Model.Constants;
using Yz.Model.Dal;
using Yz.Model.Entities;

namespace Yz.DataAccess.DbAccessses
{
    public class YzInitializer : IYzInitializer
    {
        /// <summary>
        /// 初始化admin
        /// </summary>
        public void AddAdmin()
        {
            var db = YzContext.GetInstance();
            if (!db.Admins.Where(p => p.State == StatusType.Enable).Any())
            {
                db.Admins.Add(new Admin()
                {
                    LoginName = DefaultConstant.Admin,
                    PassWord = DefaultConstant.Password
                });
                db.SaveChanges();
            }
        }
    }
}
